package com.minimalist.basic.controller.tc;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.tc.entity.vo.order.TcOrderQueryVO;
import com.minimalist.common.entity.tc.entity.vo.order.TcOrderVO;
import com.minimalist.common.feign.client.tc.TcOrderFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "停车_订单管理")
@RequestMapping("/tc/order")
public class TcOrderController{
    private static final Logger log = LoggerFactory.getLogger(TcOrderController.class);


    @Autowired
    private TcOrderFeignClient feignClient;

    @PostMapping("/add")
    @SaCheckPermission("tc:order:add")
    @Operation(summary = "添加订单")
    public R<?> add(
            @RequestBody @Validated(Add.class) TcOrderVO orderVO){
        return feignClient.addOrder(orderVO);
    }

//    @DeleteMapping("/delete")
//    @SaCheckPermission("tc:order:delete")
//    @Operation(summary = "删除订单 -> 根据订单ID删除")
//    public R<?> delete(
//            @RequestParam("orderId") @NotNull(message = "订单ID不能为空") @Parameter(name = "orderId", required = true, description = "订单ID") Long orderId){
//        return feignClient.deleteOrder(orderId);
//    }

    @PutMapping("/update")
    @SaCheckPermission("tc:order:update")
    @Operation(summary = "修改订单")
    public R<?> update(
            @RequestBody @Validated(Update.class) TcOrderVO orderVO){
        return feignClient.updateOrder(orderVO);
    }

    @GetMapping("/getPageList")
    @SaCheckPermission("tc:order:get")
    @Operation(summary = "查询订单列表(分页)")
    public R<PageResp<TcOrderVO>> getPageList(TcOrderQueryVO queryVO){
        return feignClient.getPageOrderList(queryVO);
    }

    @GetMapping("/get/{orderId}")
    @SaCheckPermission("tc:order:get")
    @Operation(summary = "根据订单ID查询订单")
    public R<TcOrderVO> get(
            @PathVariable(value = "orderId") @NotNull(message = "订单ID不能为空") @Parameter(name = "orderId", description = "参数ID", required = true) Long orderId){
        return feignClient.getOrder(orderId);
    }

    @PostMapping("/importExcel")
    @SaCheckPermission("tc:order:add")
    @Operation(summary = "Excel导入订单数据")
    public R<Map<String, Object>> importExcel(
            @RequestParam("file") MultipartFile file){
        return feignClient.importExcel(file);
    }
}
